<?php
/**
 * Created by PhpStorm.
 * User: LG
 * Date: 2018/8/2
 * Time: 18:12
 */


$conn = null;

//建库
newdb();

//创建后台管理用户表
newTable_manage_user();

//创建后台管理媒体设备log信息
newTable_manage_showInfo();

//创建设备app手机硬件信息
newTable_device_appInfo();

//创建后台管理媒体系统开关
newTable_mediaSwitchInfo();


//创建所有设备和系统实时状态
newTable_all_state();

//创建监控表
newTable_monitoring_log();


/**
 * 创建后台管理用户表
 */
function newTable_manage_user()
{
    $servername = "localhost";
    $username = "root";
    $password = "000000";

    $con = mysql_connect($servername, $username, $password);
    if (!$con) {
        die('Could not connect: ' . mysql_error());
    }

    mysql_select_db("internetofthingsdb", $con);
    $createtable = "create table manage_user(id int(10) UNSIGNED AUTO_INCREMENT PRIMARY KEY,user_name text,password text, phone text)";
    mysql_query($createtable, $con);

    mysql_close($con);
}


/**
 * 创建设备app手机硬件信息
 */
function newTable_device_appInfo()
{

    $servername = "localhost";
    $username = "root";
    $password = "000000";

    $con = mysql_connect($servername, $username, $password);
    if (!$con) {
        die('Could not connect: ' . mysql_error());
    }

    mysql_select_db("internetofthingsdb", $con);
    $createtable = "create table device_appInfo(id int(10) UNSIGNED AUTO_INCREMENT PRIMARY KEY,user_name text,password text, phone int(11))";
    mysql_query($createtable, $con);

    mysql_close($con);

}

/**
 * 创建后台管理媒体设备log信息
 */
function newTable_manage_showInfo()
{
    $servername = "localhost";
    $username = "root";
    $password = "000000";

    $con = mysql_connect($servername, $username, $password);
    if (!$con) {
        die('Could not connect: ' . mysql_error());
    }

    mysql_select_db("internetofthingsdb", $con);
    $createtable = "create table manage_device_log(log_id text,modular_id text,happen_time text,divice_id text,divice_name text,belong_type text,divice_state text,device_log text,remarks text,is_dele int(2))";
    mysql_query($createtable, $con);

    mysql_close($con);

}


/**
 * 创建后台管理媒体设备log信息
 */
function newTable_monitoring_log()
{
    $servername = "localhost";
    $username = "root";
    $password = "000000";

    $con = mysql_connect($servername, $username, $password);
    if (!$con) {
        die('Could not connect: ' . mysql_error());
    }

    mysql_select_db("internetofthingsdb", $con);
    $createtable = "create table manage_monitoring_log(log_id text,modular_id text,happen_time text,divice_id text, pic_size text,pic_resolution text,shutter_speed text,img text,is_look int(2))";
    mysql_query($createtable, $con);

    mysql_close($con);

}


/**
 * 创建后台管理媒体设备log信息
 */
function newTable_all_state()
{
    $servername = "localhost";
    $username = "root";
    $password = "000000";

    $con = mysql_connect($servername, $username, $password);
    if (!$con) {
        die('Could not connect: ' . mysql_error());
    }

    mysql_select_db("internetofthingsdb", $con);
    $createtable = "create table manage_all_state(comm_state text,system_state text,hardware_heal text,service_state text,media_moudle_state text,visit_moudle_state text,monitor_moudle_state text,power_moudle_state text,
comm_moudle_state text,hardware_state text,hard_monitor_state text,sensor_state text,hard_relay_state text,controlled_hardware_state text,terminal_state text,
tran_channel_state text)";
    mysql_query($createtable, $con);

    mysql_close($con);

}


/**
 * 创建后台管理媒体系统开关
 */
function newTable_mediaSwitchInfo()
{
    $servername = "localhost";
    $username = "root";
    $password = "000000";

    $con = mysql_connect($servername, $username, $password);
    if (!$con) {
        die('Could not connect: ' . mysql_error());
    }

    mysql_select_db("internetofthingsdb", $con);
    $createtable = "create table manage_media_switch(modularid int(12),media_service int(2), media_ui int(2),media_vioce int(2),media_cancat int(2),media_all_finaldevice int(2),media_all_mediadevice int(2))";

    mysql_query($createtable, $con);

    mysql_close($con);

}


/**
 * 创建数据库
 */
function newdb()
{
    $servername = "localhost";
    $username = "root";
    $password = "000000";

    $con = mysql_connect($servername, $username, $password);
    if (!$con) {
        die('Could not connect: ' . mysql_error());
    }

    if (mysql_query("CREATE DATABASE internetofthingsdb", $con)) {
        echo "Database created";
    } else {
        echo "Error creating database: " . mysql_error();
    }
    mysql_close($con);


}